<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2 :style={opacity}>Vue生命周期</h2>
        <button @click="opacity = 1">设置透明度为1</button>
        <button @click='stop'>点击停止变化</button>
    </div>
</body>
<script>
   Vue.config.productionTip = false //组织vue在启动时生成生产提示

    new Vue({
        el:'#root',
        data:{
          opacity:1
        },
        methods: {
            stop(){
                this.$destroy()
            }
        },
        mounted() {
            this.timer = setInterval(()=>{
                this.opacity -= 0.01
                if(this.opacity <= 0 ) this.opacity = 1
            },16)
        },
        beforeDestroy() {
            clearInterval(this.timer)
        },
    })
</script>
</html>